﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace HengTong.DataAccess.Migrations
{
    /// <inheritdoc />
    public partial class 调整物料属性数据结构 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_SysMaterialSkuAttributes_SysMaterialAttribute_AttributeId",
                table: "SysMaterialSkuAttributes");

            migrationBuilder.RenameColumn(
                name: "AttributeId",
                table: "SysMaterialSkuAttributes",
                newName: "ValueId");

            migrationBuilder.RenameIndex(
                name: "IX_SysMaterialSkuAttributes_AttributeId",
                table: "SysMaterialSkuAttributes",
                newName: "IX_SysMaterialSkuAttributes_ValueId");

            migrationBuilder.AddColumn<decimal>(
                name: "Order",
                table: "SysMaterialAttribute",
                type: "decimal(8,2)",
                nullable: false,
                defaultValue: 0m);

            migrationBuilder.AddColumn<int>(
                name: "Version",
                table: "SysMaterial",
                type: "int",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.CreateTable(
                name: "SysMaterialAttributeValue",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    AttributeId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    Value = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    UpdateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysMaterialAttributeValue", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SysMaterialAttributeValue_SysMaterialAttribute_AttributeId",
                        column: x => x.AttributeId,
                        principalTable: "SysMaterialAttribute",
                        principalColumn: "ID");
                });

            migrationBuilder.CreateIndex(
                name: "IX_SysMaterialAttributeValue_AttributeId",
                table: "SysMaterialAttributeValue",
                column: "AttributeId");

            migrationBuilder.AddForeignKey(
                name: "FK_SysMaterialSkuAttributes_SysMaterialAttributeValue_ValueId",
                table: "SysMaterialSkuAttributes",
                column: "ValueId",
                principalTable: "SysMaterialAttributeValue",
                principalColumn: "ID");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_SysMaterialSkuAttributes_SysMaterialAttributeValue_ValueId",
                table: "SysMaterialSkuAttributes");

            migrationBuilder.DropTable(
                name: "SysMaterialAttributeValue");

            migrationBuilder.DropColumn(
                name: "Order",
                table: "SysMaterialAttribute");

            migrationBuilder.DropColumn(
                name: "Version",
                table: "SysMaterial");

            migrationBuilder.RenameColumn(
                name: "ValueId",
                table: "SysMaterialSkuAttributes",
                newName: "AttributeId");

            migrationBuilder.RenameIndex(
                name: "IX_SysMaterialSkuAttributes_ValueId",
                table: "SysMaterialSkuAttributes",
                newName: "IX_SysMaterialSkuAttributes_AttributeId");

            migrationBuilder.AddForeignKey(
                name: "FK_SysMaterialSkuAttributes_SysMaterialAttribute_AttributeId",
                table: "SysMaterialSkuAttributes",
                column: "AttributeId",
                principalTable: "SysMaterialAttribute",
                principalColumn: "ID");
        }
    }
}
